package com.demo.controller;

import com.demo.common.model.R;
import com.demo.entity.ActivityRemark;
import com.demo.service.ActivityRemarkService;
import com.demo.vo.ActivityRemarkVO;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/activity/remark")
@RestController
public class ActivityRemarkController {
    @Autowired
    private ActivityRemarkService activityRemarkService;

    /**
     * 根据市场活动标识分页查询备注列表
     */
    @GetMapping("/page")
    public R<PageInfo<ActivityRemarkVO>> loadActivityRemarkPage(@RequestParam Integer activityId,
                                                    @RequestParam Integer current,
                                                    @RequestParam(required = false,defaultValue = "10")Integer pageSize){
        PageInfo<ActivityRemarkVO> pageInfo = activityRemarkService.queryActivityRemarkPageByActivityId(activityId,current,pageSize);
        return R.OK(pageInfo);
    }
    /**
     * 保存市场活动备注
     */
    @PostMapping
    public R<String> saveActivityRemark(@RequestBody ActivityRemark activityRemark){
        boolean saved = activityRemarkService.save(activityRemark);
        return saved ? R.OK(null) : R.FAIL("市场活动保存失败");
    }
    /**
     * 删除市场活动
     */
    @DeleteMapping("/{id}")
    public R<String> removeActivityRemark(@PathVariable Integer id){
        boolean result = activityRemarkService.removeById(id);
        return  result ? R.OK(null) : R.FAIL("删除市场失败");
    }
    /**
     * 修改市场活动备注内容
     */
    @PutMapping
    public R<String> updateActivityRemark(@RequestBody ActivityRemark activityRemark){
        boolean result = activityRemarkService.updateById(activityRemark);
        return  result ? R.OK(null) : R.FAIL("修改失败");
    }
}
